package br.ufmg.dcc.vod.remoteworkers.async;

import java.util.LinkedList;

public class CommandQueue<T> {

	private final LinkedList<T> eventQueue;

	public CommandQueue() {
		this.eventQueue = new LinkedList<T>();
	}

	public synchronized void put(T event) {
		eventQueue.addLast(event);
		notify();
	}

	public synchronized T blockingRemove() {
		try {
			while (eventQueue.size() == 0) {
				wait();
			}
		} catch (InterruptedException e) {
		}
		return eventQueue.removeFirst();
	}

	public synchronized int size() {
		return eventQueue.size();
	}
}